// ES6可以继承原生构造函数定义子类，因为ES6是先新建父类的实例对象this，然后再用子类的构造函数修饰this

class VersionedArray extends Array {
	constructor() {
		super();
		this.history = [[]];
	}
	commit() {
		this.history.push(this.slice());
	}
	revert() {
		this.splice(0, this.length, ...this.history[this.history.length - 1]);
	}
}

const x = new VersionedArray();

x.push(1);
x.push(2);
x; // [1, 2]
x.history; // [[]]

x.commit();
x.history; // [[], [1, 2]]

x.push(3);
x; // [1, 2, 3]
x.history; // [[], [1, 2]]

x.revert();
x; // [1, 2]